package com.douxg.fastCoding.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.douxg.fastCoding.spring.base.MyBaseController;
import com.douxg.fastCoding.spring.vo.Result;
import com.douxg.fastCoding.web.entity.Dict;
import com.douxg.fastCoding.web.service.DictService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description
 * @Auther douxg
 * @Date 2021/6/16 18:48
 */
@RestController
@RequestMapping("fc/dict")
public class DictController extends MyBaseController {
    @Resource
    private DictService service;

    @PostMapping("insert")
    public Result insert(@RequestBody Dict dto) {
        boolean handleResult = service.save(dto);
        if (handleResult) {
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("update")
    public Result update(@RequestBody Dict dto) {
        boolean handleResult = service.updateById(dto);
        if (handleResult) {
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("delete")
    public Result delete(@RequestBody Dict dto) {
        boolean handleResult = service.removeById(dto.getId());
        if (handleResult) {
            return Result.success();
        }
        return Result.error();
    }

    @PostMapping("page")
    public Result page(@RequestBody Dict dto) {
        IPage<Dict> cfgIPage = service.mySelectPage(dto);
        return Result.success(cfgIPage);
    }

    @PostMapping("listByType")
    public Result listByType(@RequestBody Dict dto) {
        return Result.success(service.listByType(dto));
    }
}
